package demo;

import java.sql.Connection;

import com.amarsoft.are.ARE;
import com.amarsoft.dexpre.Tools;
import com.amarsoft.dexpre.bean.FilledParam;
import com.amarsoft.dexpre.comm.BizProcesser;
import com.amarsoft.dexpre.exception.DEException;
import com.amarsoft.dexpre.exception.ServerBizException;

public class Demo3BizProcesser extends BizProcesser {

	public void createErrorMsg(Exception e){
		String errMsg = "";
		if(e instanceof ServerBizException){
			errMsg = e.getMessage();
		}else{
			errMsg = "Unknown System Error";
		}
		ARE.getLog().debug(errMsg);
		FilledParam fParam = new FilledParam();
		fParam.putDefaultValue("RESNO", "T001");
		fParam.putDefaultValue("RESULT", "2");
		Connection conn = null;
		try {
			conn = Tools.getConnection();
			transaction.fillMessage(fParam, conn);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		Tools.closeDB(conn, null, null);
		
	}

	public void dispose() throws DEException {
		if(transaction.getID().equals("DEXPRE_TRANS_SERVER5")){
			FilledParam fParam = new FilledParam();
			
			fParam.putDefaultValue("RESNO", "F005");
			fParam.putDefaultValue("RESULT", "1");
			
			fParam.putDefaultValue("ACCOUNTNO", transaction.getInboundMessages().get("SNDS_FEE_REQ").getFieldValue("ACCOUNTNO"));
			fParam.putDefaultValue("STATUS", "S");
			
			Connection conn = null;
			throw new ServerBizException("99999999999999999999");
//			try {
//				conn = Tools.getConnection();
//				transaction.fillMessage(fParam, conn);
//			} catch (Exception e1) {
//				e1.printStackTrace();
//			}
//			Tools.closeDB(conn, null, null);
		}else if (transaction.getID().equals("DEXPRE_TRANS_SERVER6")){
			FilledParam fParam = new FilledParam();
			
			fParam.putDefaultValue("RESNO", "F006");
			fParam.putDefaultValue("RESULT", "1");
			
			fParam.putDefaultValue("CUSID", transaction.getInboundMessages().get("SNDS_CUSTOMER_INFO_REQ").getFieldValue("CUSID"));
			fParam.putWhereSql("SNDS_CUSTOMER_INCOMOE", "where 1=1");
			Connection conn = null;
//			throw new ServerBizException("99999999999999999999");
			try {
				conn = Tools.getConnection();
				transaction.fillMessage(fParam, conn);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			Tools.closeDB(conn, null, null);
		}
	}
}
